<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-card class="box-card">
      <div class="query-card">
        <!-- <el-row type="flex" align="middle">
        <el-col :span="12">-->
        <div class="grid-content bg-purple search">
          <el-radio-group v-model="picktime" @change="changeDate">
            <el-radio-button label="1">今天</el-radio-button>
            <el-radio-button label="2">近半月</el-radio-button>
            <el-radio-button label="3">最近一个月</el-radio-button>
          </el-radio-group>
          <el-form ref="query" :model="query" label-width="100px">
            <el-form-item style="margin-bottom:0px" label="关键字">
                <i slot="label" class="el-icon-search" style="font-size:20px"></i>
              <el-input style="width:360px" v-model="query.keywords" placeholder="请输入用户手机号/订单编号搜索"></el-input>
            </el-form-item>
            <el-form-item style="margin-bottom:0px" label="操作日期">
              <el-date-picker
                ref="picker"
                v-model="query.timeArr"
                type="daterange"
                align="right"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </div>
        <!-- </el-col> -->
        <!-- <el-col :span="12"> -->
        <div class="grid-content bg-purple-light">
          <el-button type="primary" @click="queryAsk">查询</el-button>
          <el-button @click="queryReset">重置</el-button>
        </div>
        <!-- </el-col>
        </el-row>-->
      </div>
    </el-card>

    <!-- 表格 -->
    <el-card class="box-card">
      <div class="head">
        <div>盲盒</div>
        <div>单价</div>
        <div>数量</div>
        <div>客户</div>
        <div>金额</div>
        <div>奖品</div>
        <div>交易类型</div>
      </div>
      <div class="order" v-for="item in tableData" :key="item.id">
        <div class="order-title">
          <div>订单号：{{item.order_sn}}</div>
          <div style="margin-left:20px">支付时间：{{item.pay_time}}</div>
        </div>
        <div class="order-info">
          <div>
            <el-avatar shape="square" :size="60" fit="fll" :src="item.box_img"></el-avatar>
            <span style="margin-left:10px">{{item.box_name}}</span>
          </div>
          <div style="padding-right: 10px;">￥{{item.price}}</div>
          <div style="padding-right: 10px;">{{item.num}}</div>
          <div style="flex-direction:column">
            <el-button type="text" @click="handleEdite(item.user_id)">{{item.nickname}}</el-button>
            <span></span>
            <span>{{item.mobile}}</span>
          </div>
          <div>{{item.pay_price}}</div>
          <div style="flex-direction:column;padding-left: 5px;">
            <el-tag>{{item.box_goods.rule_name}}</el-tag>
            <el-tag>{{item.box_goods.price}}</el-tag>
          </div>
          <div style="padding-left: 12px;">
            <el-tag v-if="item.pay_type==1">微信支付</el-tag>
            <el-tag v-if="item.pay_type==2">支付宝</el-tag>
            <el-tag v-if="item.pay_type==3">余额</el-tag>
            <el-tag v-if="item.pay_type==4">积分</el-tag>
          </div>
        </div>
      </div>
      <div style="margin-top:20px;text-align:right">
        <el-pagination
          background
          layout="prev, pager, next"
          :current-page="currentPage"
          :total="total"
          @current-change="currentChange"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { blindBoxOrderList } from "@/api/order";
import { parseTime } from "@/utils/index";

export default {
  name: "blindOrder",
  props: {
    user_id: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      // 分页数据
      total: 0,
      currentPage: 1,
      pageSize: 10,
      //query
      query: {
        keywords: "",
        add_time: "",
        timeArr: []
      },
      options: "",
      tableData: [],
      loading: false,
      picktime: "1",
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", [new Date(), new Date()]);
            }
          },
          {
            text: "近半月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      }
    };
  },
  mounted() {
    // 默认今天
    this.query.timeArr = [new Date(), new Date()];
    // this.getList();
  },
  methods: {
    async getList() {
      this.loading = true;
      this.query.add_time =
        parseTime(this.query.timeArr[0], "{y}-{m}-{d}") +
        "," +
        parseTime(this.query.timeArr[1], "{y}-{m}-{d}");
      const res = await blindBoxOrderList({
        page: this.currentPage,
        limit: this.pageSize,
        keywords: this.query.keywords,
        user_id: this.user_id,
        add_time: this.query.add_time
      });
      console.log(res);
      this.loading = false;
      this.total = res.count;
      this.tableData = res.data;
      this.tableData.forEach(item => {
        item.pay_time = parseTime(item.pay_time, "{y}-{m}-{d} {h}:{i}:{s}");
      });
    },
    changeDate() {
      console.log(this.picktime);
      if (this.picktime == 1) {
        this.$set(this.query, "timeArr", [new Date(), new Date()]);
        this.getList();
      } else if (this.picktime == 2) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
        this.$set(this.query, "timeArr", [start, end]);
        this.getList();
      } else if (this.picktime == 3) {
        const end = new Date();
        const start = new Date();
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
        this.$set(this.query, "timeArr", [start, end]);
        this.getList();
      }
    },
    queryAsk() {
      console.log(this.query);
      this.currentPage = 1;
      this.getList();
    },
    queryReset() {
      this.resetForm("query");
      this.total = 0;
      this.currentPage = 1;
      this.pageSize = 10;
      this.query.add_time = "";
      this.query.user_id = "";
      this.query.keywords = "";
      this.query.timeArr = [new Date(), new Date()];
      this.picktime = 1;
      this.getList();
    },
    //分页改变
    currentChange(current) {
      this.currentPage = current;
      this.getList();
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 跳转用户
    handleEdite(id) {
      this.$router.push({ path: "/consumer/consumeroprate", query: { id:id } });
    },
  }
};
</script>

<style lang="scss" scoped>
.query-card {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  // ::v-deep .el-input--medium .el-input__inner {
  //   width: 360px;
  // }
  .box-card {
    margin-bottom: 20px;
  }
  .search {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
  }
}
::v-deep .el-drawer.rtl {
  width: 650px !important;
  overflow: auto;
}
.query-card {
  ::v-deep .el-form {
    display: flex;
    flex-wrap: wrap;
  }
}

::v-deep .el-drawer.rtl {
  padding-bottom: 20px;
  width: 1000px !important;
  overflow: auto;
}
//订单列表
.head {
  display: flex;
  width: 100%;
  border-bottom: 1px solid #d4d4d4;
  line-height: 40px;
  div {
    width: 14.3%;
    text-align: center;
  }
}
.order {
  width: 100%;
  margin-top: 15px;
  .order-title {
    display: flex;
    width: 100%;
    background-color: #e8ecf1;
    padding: 0 10px;
    line-height: 40px;
    font-size: 14px;
  }
  .order-info {
    display: flex;
    height: 80px;
    padding: 10px;
    border-bottom: 1px solid #d4d4d4;
    div {
      width: 14.3%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
    }
  }
}
</style>